<template>
    <div class="newsinfo-container">
        <!-- 大标题 -->
        <h3 class="title">{{ newsinfo.title }}</h3>
        <!-- 子标题 -->
        <p class="subtitle">
            <span>发表时间:{{ newsinfo.add_time | dataFormat }}</span>
            <span>点击:{{ newsinfo.click }}次</span>
        </p>
        <!-- 设定一条横线横线 -->
        <hr>
        <!-- 内容区域 -->
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    // 先导入要注册的组件
    import comment from '../subcomponents/comment.vue'
    export default {
        data() {
            return {
                // 将 URL 请求回来的 id 值读取过来 然后挂在在 data上
                id: this.$route.params.id,
                newsinfo: {},
            }
        },
        created() {
            this.getNewsinfo()
        },
        methods: {
            getNewsinfo() {
                this.$http.get('http://www.liulongbin.top:3005/api/getnew/' + this.id).then(result => {
                    if (result.body.status === 0) {
                        this.newsinfo = result.body.message[0]
                        // console.log(result.body.message[0])
                    } else {
                        Toast('获取信息失败!')
                    }
                })
            }
        },
        components: {
            // 用来注册子组件的节点
            "comment-box": comment
        }
    }
</script>

<style lang="scss" scoped>
    .newsinfo-container {
        padding: 0 4px;

        .title {
            font-size: 16px;
            text-align: center;
            margin: 10px 0;
            color: red;
        }

        .subtitle {
            font-size: 13px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }

        .content {}
    }
</style>